package com.ash.service.message;

import com.ash.domain.Message;
import com.ash.domain.vo.MessageVo;
import com.ash.mapper.message.MessageMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/4/3 20:21
 * @file : project06.com.ash.service.message.MessageServiceImpl.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
public class MessageServiceImpl implements MessageService {
    @Resource
    MessageMapper messageMapper;
    @Override
    public Integer add(Message message) {
        return messageMapper.add(message);
    }

    @Override
    public List<MessageVo> selectByRole(Integer rid, Integer startPage, Integer size) {
        if (startPage != null && size != null) {
            return messageMapper.selectByRole(rid,(startPage-1)*size,size);
        }
        else{
            return messageMapper.selectByRole(rid,null,null);
        }
    }

    @Override
    public Integer dataCount(Integer rid) {
        return messageMapper.dataCount(rid);
    }

    @Override
    public int delete(int mid) {
        return messageMapper.delete(mid);
    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        return messageMapper.deleteByIds(ids);
    }

    @Override
    public List<MessageVo> selectByToId(Integer toId, Byte hadRead, Integer page, Integer limit) {
        if(page!=null&&limit!=null){
            return messageMapper.selectByToId(toId, hadRead, (page-1)*limit, limit);
        }
        else{
            return messageMapper.selectByToId(toId, hadRead, null, null);
        }
    }

    @Override
    public Integer selectByToIdCount(Integer toId, Byte hadRead) {
        return messageMapper.selectByToIdCount(toId,hadRead);
    }

    @Override
    public Integer update(List<Integer> ids, Integer toId) {
        return messageMapper.update(ids,toId);
    }
}
